#ifndef DATABASEMANAGE_H
#define DATABASEMANAGE_H
#include"smallhistory.h"
#include <QWidget>
#include<QSql>
#include<QSqlDatabase>
#include<QSqlQuery>
#include<QListWidget>
#include"firstcollectvideo.h"
#include"privateinfo.h"
#include"historicalwatch.h"
#include"onevideoinfo.h"
#include"frienditem.h"
#include"mysendmes.h"
#include"othersendmes.h"
class databasemanage : public QWidget
{
    Q_OBJECT
public:
    explicit databasemanage(QWidget *parent = nullptr);
public:
    QSqlDatabase database;
    QSqlQuery* sq;
    QSqlQuery* sql;
public:
    int createnewudpsocket();
    bool judgeresonable(QString account,QString secret="");   //判断用户是否存在及合法,secret为空代表是判断是否能够注册
    void complementprivateinfo(QString account,privateinfo* pri);   //补充用户信息
    void insertprivateinfo(QString name,QString image,QString sign,QString account,QString secret);  //插入数据到privateinfo表中
    void updateinfo(QString table, QString probeitem, QString situation,QString attribute,QString newvalue);
    void updatefriendrelation(QString type,QString people,QString friends);
    bool isfriend(QString people,QString friends);
    void insertvideoevaluation(int id,QString people,QString time,QString content_type,QString content,bool istalk,QString position,QString image);
    void addhistoricalwatch(QString people,QString watchtime,QString watchlength,int videoid);
    void loadhistoricalwatch(historicalwatch* his,privateinfo* pri);
    void complementpersonalcollect(QString people);   //
    void addonecollect(privateinfo* pri,QString collectname,QString firstimage);
    void addonemyvideo(onevideoinfo* ones);  //添加一条个人视频
    void loadmyvideo(QString people,QVector<onevideoinfo*>& ones);  //通过用户名字加载个人视频(存放到ones数组中去)
    //初始化个人收藏集
    void initcollects(QString people,QHash<QString,QVector<int>>& collects,QHash<QString,firstcollectvideo*>& collectsfirstimage);
    void addonevideotocollect(QString people,QString collectname,int videoid); //添加一个视频到收藏夹中
    void loadfriendrelation(QString people,QHash<QString,frienditem*>& friends);  //将用户的朋友填充到数组里面
    void addfriendrelation(QString people,QString fri,QString friendimage,int friendudpsocket);
    void removefriendrelation(QString people,QString fri);
    void addonefriendmes(QString people ,QString fri,QString content_type,QString content);
    void loadfriendmes(QString people,QHash<QString,QVector<mysendmes*>>& ms,QHash<QString,QVector<othersendmes*>>& os); //好友名和消息的映射关系
    bool judgefavor(int videoid,QString people);
    bool judgecoin(int videoid,QString people);
    bool judegecollect(int videoid,QString people);
    void addfavor(int videoid,QString people);
    void addcoin(int videoid,QString people);
    void addcollect(int videoid,QString people);
    void reducefavor(int videoid,QString people);
    void reducecoin(int videoid,QString people);
    void reducecollect(int videoid,QString people);
signals:
    void addsmallhistory(QString image,QString author,QString time,QString sign);
};

#endif // DATABASEMANAGE_H
